<template>
    <div>
        <x-table class="tableBox">
            <!-- <tr class="t_list_caption">
                <th colspan="3">修改密码</th>
            </tr> -->
            <tr class="t_td_text">
                <td>旧密码：</td>
                <td><input type="password" v-model="oldPassword" min="6" max="15" placeholder="请输入您的旧密码" /></td>
            </tr>
            <tr class="t_td_text">
                <td>新密码：</td>
                <td><input type="password" v-model="password" min="6" max="15" placeholder="密码必须为6-15位字母和数字组合" /></td>
            </tr>
            <tr class="t_td_text">
                <td>确认密码：</td>
                <td><input type="password" v-model="rePassword" min="6" max="15" placeholder="请确认登录密码，两次密码需要一致" /></td>
            </tr>
        </x-table>
        <input type="button" @click="submitFun" class="submitBtn" value="确认" />
    </div>
</template>
<style scoped>
    .tableBox{
        background-color: #fff;
        text-align: center;
        width: 100%;
        margin-top: 30px;
    }
    .tableBox th{
        background: #e2d4ca;
        border-bottom: 1px solid #c3b1a4;
        border-top: 1px solid #ebe1d9;
        font-size: 12px;
        line-height: 22px;
        font-weight: bold;
    }
    .tableBox tr{
        font-size: 12px;
    }
    .tableBox input{
        display: block;
        width: 80%;
        margin: 0px auto;
        padding: 5px 5px;
        border-radius: 3px;
        border: 1px solid #d3d3d3;
    }
    .submitBtn{
        background: #6b250b;
        border: 1px solid #6b250b;
        color: #fff;
        display: block;
        width: 85%;
        margin: 28px auto 0px;
        line-height: 36px;
        border-radius: 5px;
    }
</style>
<script>

    import axios from 'axios'
    import {lotterytype} from '../../../../assets/js/lotterytype.js'
    import { XTable } from 'vux'

    export default {
        name: "ChangePassword",
        props: {  //普通类型：String、Number、Boolean、Null    引用类型： Array、Object
            
        },
        components: {
            XTable
        },
        data(){
            return{
                oldPassword: '',
                password: '',
                rePassword: '',
            }
        },
        methods: {
            //修改密码
            submitFun(){
                var _this = this;
                if(_this.oldPassword.length < 5 || _this.oldPassword.length > 16 || !_this.validateJyh(_this.password) ){
                    
                    alert('旧密码必须为6-15位字母和数字组合');
                    return;
                }
                if(_this.password.length < 5 || _this.password.length > 16 || !_this.validateJyh(_this.password) ){

                    alert('新密码必须为6-15位字母和数字组合');
                    return;
                }
                if(_this.rePassword.length < 5 || _this.rePassword.length > 16 || !_this.validateJyh(_this.password) ){
                    
                    alert('确认密码必须为6-15位字母和数字组合');
                    return;
                }
                
                if(_this.password != _this.rePassword){
                    alert('两次密码输入不一致');
                    return;
                }

                this.$httpPut('/api/account/changePassword',{
                        'oldPassword': _this.oldPassword,
                        'password': _this.password,
                        'rePassword': _this.rePassword,
                    }).then(response => {
                        
                        if(response.status == 200){
                            alert('修改成功！');
                        }

                });

            },
            validateJyh(glhm){//校验关联交易号 
                console.log(glhm);
                
                var reg = /[0-9]+[a-zA-Z]+[0-9a-zA-Z]*|[a-zA-Z]+[0-9]+[0-9a-zA-Z]*/; 
                console.log(reg.test(glhm));
                if(!reg.test(glhm)){ 
                    return false;
                }else{
                    return true;
                }
            },
            
        },
        mounted(){
            //当前标题
            this.$emit('getTit','修改密码');
        },
        watch: {
            openBet: function(now,old){
                // console.log(now,old);
                //开奖  刷新路珠数据
                this.init();
                
            },
            ninetime: function(now,old){
                console.log('------------90s  账户信息');
                //90s  刷新数据
                this.init();
            },

        },
    }
</script>
